package test;

public class CheckAccount extends Account{
    public CheckAccount(int id, double balance, double annualInterestRate) {
        super(id, balance, annualInterestRate);
    }
    public CheckAccount(int id, double balance, double annualInterestRate,int overdraft) {
        super(id, balance, annualInterestRate);
        this.overdraft=overdraft;
    }
    private double overdraft;

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(int overdraft) {
        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(double amount) {
        if (amount<balance){
            balance=balance-amount;
            System.out.println("你的账户余额为："+balance);
            System.out.println("你的可透支额度为："+overdraft);
        }else if (amount>balance){
            if (amount>(balance+overdraft)){
                System.out.println("超过可透支额度");
                System.out.println();
                System.out.println("你的账户余额为："+balance);
                System.out.println("你的可透支额度为："+overdraft);
            }else if (amount<(balance+overdraft)){
                overdraft=(overdraft+balance)-amount;
                balance=0;
                System.out.println("你的账户余额为："+balance);
                System.out.println("你的可透支额度为："+overdraft);
            }
        }
    }
}
